package org.example.mapper;

import org.apache.ibatis.annotations.Mapper;
import org.apache.ibatis.annotations.Param;
import org.apache.ibatis.annotations.Select;
import org.example.pojo.User;

import java.util.List;

@Mapper
// 应用程序在运行时，会自动为 UserMapper 接口生成一个实现类，这个实现类会通过反射的方式，调用数据库
public interface UserMapper {

    // 查询所有用户信息
    public List<User> findAll();

    // 删除
    /*@Select("delete from user where id = #{id}")*/
    public Integer deleteById(Integer id);

    // 添加
    /*@Select("insert into user(username, password, name, age) " +
            "values(#{username}, #{password}, #{name}, #{age})")*/
    public Integer insert(User user);

    // 更新
    /*@Select("update user set username=#{username}, password=#{password}, name=#{name}, age=#{age} where id=#{id}")*/
    public Integer update(User user);

    // 查询
    @Select("select * from user where username= #{username} and password = #{password}")
    //public User findByUsernameAndPassword(User user);
    public User findByUsernameAndPassword(@Param("username") String username, @Param("password") String password);
}
